#!/usr/bin/python
# -*- coding: utf-8 -*-
import json
from datetime import datetime
import utlis


class UserEncoder(json.JSONEncoder):
    def default(self, obj):
        if isinstance(obj, datetime):
            return obj.__str__()
        return json.JSONEncoder.default(self, obj)


class Author(object):
    def __init__(self, data):
        self.id = data['id']
        self.idnew = utlis.toString(data['idnew'])
        self.nameStr = utlis.toString(data['nameStr'])
        content = utlis.toString(data['cont'])
        content = content.replace("'", "\\\'")
        content = content.replace('"', '\\\"')
        self.cont = content
        self.chaodai = utlis.toString(data['chaodai'])
        self.pic = utlis.toString(data['pic'])
        self.likes = data['likes']
        self.ipStr = utlis.toString(data['ipStr'])
        self.creTime = utlis.toString(data['creTime'])
        self.shiCount = data['shiCount']

    def obj_2_json(self):
        return {
            'id': self.id,
            'idnew': self.idnew,
            'nameStr': self.nameStr,
            'cont': self.cont,
            'chaodai': self.chaodai,
            'pic': self.pic,
            'likes': self.likes,
            'ipStr': self.ipStr,
            'creTime': self.creTime,
            'shiCount': self.shiCount
        }
